package com.lagou.mr.output;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class CustomOutputFormat extends FileOutputFormat<Text, NullWritable> {


    @Override
    public RecordWriter<Text, NullWritable> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException {
        Configuration configuration = context.getConfiguration();
        FileSystem fs = FileSystem.get(configuration);
        FSDataOutputStream lagouOut = fs.create(new Path("E:\\output\\outputFormat\\lagou.log"));
        FSDataOutputStream otherOut = fs.create(new Path("E:\\output\\outputFormat\\other.log"));
        CustomWriter writer = new CustomWriter(lagouOut, otherOut);
        return writer;
    }
}
